home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / scheme / schmlbrr / schem_lb.lha / unsupported / CScheme / scoops.doc < prev    next >
Encoding:
Text File  |  1993-07-16  |  11.1 KB  |  302 lines

  1. SCOOPS - the Scheme Object-Oriented Programming System
  2.  
  3. Documentation for the version for MIT Scheme 7.1
  4. ------------------------------------------------
  5.  
  6. Notes originally by Steve Sherin; revamped by Peter Ross, Dept of AI, 
  7. University of Edinburgh, 6 May 1991.
  8.  
  9.  
  10.  
  11. SCOOPS is copyright Texas Instruments; the following copyright notice
  12. appears in the software:
  13.  
  14. ;;;
  15. ;;;    Copyright (c) 1986 Texas Instruments Incorporated
  16. ;;;
  17. ;;;    Permission to copy this software, to redistribute it, and
  18. ;;;     to use it for any purpose is granted, subject to the
  19. ;;;     following restrictions and understandings.
  20. ;;;
  21. ;;;    1. Any copy made of this software must include this copyright
  22. ;;;    notice in full.
  23. ;;;
  24. ;;;    2.  All materials developed as a consequence of the use of
  25. ;;;    this software shall duly acknowledge such use, in accordance
  26. ;;;    with the usual standards of acknowledging credit in academic
  27. ;;;    research.
  28. ;;;
  29. ;;;    3. TI has made no warranty or representation that the
  30. ;;;    operation of this software will be error-free, and TI is
  31. ;;;    under no obligation to provide any services, by way of
  32. ;;;    maintenance, update, or otherwise.
  33. ;;;
  34. ;;;    4.  In conjunction with products arising from the use
  35. ;;;    of this material, there shall be no use of the name of
  36. ;;;    Texas Instruments (except for the above copyright credit)
  37. ;;;    nor of any adaptation thereof in any advertising, promotional,
  38. ;;;    or sales literature without prior written consent from TI in
  39. ;;;    each case.
  40.  
  41.  
  42.  
  43. Getting started
  44. ---------------
  45.  
  46. You may have to find the file scoops.scm which contains the full
  47. source. You can load it to get an interpreted version; there may be one
  48. or both of scoops.bin and scoops.com in the same directory. To load,
  49. just do
  50.         (load "<WHEREVER>/scoops")
  51. and the loader will find the fastest-running version of the three
  52. loadable forms.
  53.  
  54. If you can only find scoops.scm, you can compile it. First start up
  55. Scheme with the compiler, by the UN*X command
  56.         % scheme -compiler
  57. which typically takes a short while. Then, to compile scoops, execute
  58.     (cf "scoops.scm")
  59. which will create both scoops.bin and scoops.com, but don't hold your
  60. breath, go for a coffee instead. Afterwards, just load the system with
  61.         (load "scoops")
  62. although you may prefer to restart Scheme without the compiler `band',
  63. in order to save space, before loading SCOOPS.
  64.  
  65. Introduction
  66. ------------
  67.  
  68. SCOOPS is an object-oriented system written in Scheme. It offers
  69. multiple rather than single inheritance, class variables as well as
  70. instance variables, run-time addition and deletion of methods, active
  71. values, and selectively settable/gettable/inittable instance variables.
  72. There is no support for method combination, either by send-super or by
  73. before/after daemons. If all this means nothing to you, it's time to go
  74. and read up about object-oriented programming; this is not a primer.
  75.  
  76. The inheritance strategy used is pure depth-first, omitting any classes
  77. already visited in the search; this is different from the `up-to-the-joins'
  78. strategy used in some other object-oriented systems such as Flavors and Loops.
  79.  
  80. Note that classes are defined in a global context.
  81.  
  82. The following section summarises the functions which comprise the user
  83. level of the SCOOPS system. 
  84.  
  85. Functions:
  86. ----------
  87.  
  88. DEFINE-CLASS
  89.      
  90.   (define-class <name> 
  91.         (mixins <parent-classes>)                              ; optional
  92.         (classvars <binding-pairs or names for default value>) ; optional
  93.         (instvars     "        "        "    )                 ; optional
  94.         (options <set-spec> <get-spec> <init-spec>))           ; optional
  95.  
  96.       The CLASSVARS and INSTVARS can be just names, in which case those
  97.       variables will be given the default value of #f, or thye can be
  98.       specified as
  99.          (name initial-value)
  100.       pairs. The specification of INSTVARS can also include forms like so:
  101.          (name (active init-value get-function set-function))
  102.       which indicates that the named variable is an active value. It will
  103.       have init-value as its initial value. The functions get-function and
  104.       set-function should be functions of one argument. When the method
  105.       called GET-name is called, the get-function will be called with the
  106.       instance variable's current value as argument. When the method
  107.       called SET-name is called, the set-function will be called with the
  108.       new value as argument. The (active ...) specifications can be
  109.       nested arbitrarily deeply, using this form for the init-value. In
  110.       such a case all the set-functions are called in order, outermost
  111.       first, when the SET-name method is invoked. All the get-functions
  112.       are called whenever the GET-name method is invoked, but innermost
  113.       first.
  114.   
  115.       Instance and class variables need not be accessed by SET-name
  116.       and GET-name methods. They can be treated as lexical variables for
  117.       the purposes of method definition, so that (say) a variable can just
  118.       be set by doing a (SET! name ...). An active value is not triggered
  119.       by such lexical access; only the use of SET-name or GET-name
  120.       triggers it.
  121.    
  122.       The <set-spec> can be
  123.          settable-variables
  124.       to cause automatic creation of methods named SET-name for all
  125.       class and instance variables. It can also be
  126.          (settable-variables <var1 .. varN>)
  127.       to cause SET-* methods to be created for only the named variables.
  128.       The <get-spec> is analogous to <set-spec>, causing creation of GET-*
  129.       methods.
  130.       
  131.       The <init-spec> can be
  132.          inittable-variables
  133.       so that keywords will be created for all instance variables for use
  134.       in a call of MAKE-INSTANCE (see below). It can also be
  135.          (inittable-variables <var1 ... varN>)
  136.       to make only some be initialisable in this way.
  137.   
  138.       Example:
  139.          (define-class warship
  140.            (mixins ship military-equipment)
  141.            (classvars 
  142.               (no-of-warships 0))
  143.            (instvars
  144.               guns
  145.               shells)
  146.            (options
  147.               (settable-variables shells)  ; cannot change guns!
  148.               gettable-variable            ; but can ask about anything
  149.               inittable-variables))        ; and specify when creating.
  150.               
  151. MAKE-INSTANCE
  152.       
  153.    (make-instance name '<var1> <val1> ... '<varN> <valN>)
  154.       returns an instance of class name with those variables bound
  155.       to those values provided they are declared inittable when the class
  156.       was defined.
  157.   
  158.       Use a variable to bind the instance returned as it does not side-effect
  159.       the environment. Example:
  160.   
  161.         (define victorious
  162.            (make-instance warship
  163.               'guns    6        ; can init this, but no set-guns method.
  164.               'shells  500      ; can init this, & there is a set-shells.
  165.               'country "tibet") ; variable presumably inherited from ship?
  166.       
  167. COMPILE-CLASS
  168.       
  169.    (compile-class <class>)  
  170.       sets up the environments for classvars and methods. This is done
  171.       automatically anyway when the first class instance is created, but 
  172.       you may prefer to cause the slight delay to happen at a time of your 
  173.       choosing. The information provided by DESCRIBE-CLASS will be 
  174.       incomplete until the class is `compiled'.
  175.   
  176.       Note that the `compilation' of a class does not force the 
  177.       compilation of its mixins, nor is it necessary for the mixins to 
  178.       be compiled before a class (or at all). The compilation merely searches  
  179.       the inheritance graph for the class variables and methods and 
  180.       creates Scheme environments in which these exist together; these
  181.       environments are used in instance creation, which is why the 
  182.       compilation happens automatically upon creation of the first 
  183.       instance. This `compilation' means that when a message is sent to
  184.       an instance, the inheritance graph does not have to be re-searched 
  185.       each time.
  186.  
  187.       However, if a class has been compiled already and then a method is 
  188.       added to or deleted from the class or any mixin, then there is no
  189.       need to recompile the class or any other class of which it is a 
  190.       mixin. SCOOPS handles this automatically.
  191.       
  192. CLASS-OF-OBJECT
  193.   
  194.    (class-of-object <obj>) 
  195.       simply returns the class-name of the class of an object.
  196.       
  197. NAME->CLASS
  198.       
  199.    (name->class '<name>)
  200.       returns the class named by <name>.
  201.       
  202. METHODS
  203.       
  204.    (methods <class>)
  205.       returns a list of names of methods available to that class and defined
  206.       within that class.
  207.       
  208. ALL-METHODS
  209.   
  210.    (all-methods <class>)
  211.       returns a list of names of methods available to the class, including 
  212.       inherited methods.
  213.   
  214. CLASSVARS
  215.   
  216.    (classvars <class>)
  217.       returns a list of the names of classvars of the class itself.
  218.       
  219. ALL-CLASSVARS
  220.   
  221.    (all-classvars <class>)
  222.       returns a list of the names of classvars of the class and all those it 
  223.       inherits from.
  224.       
  225. INSTVARS
  226.   
  227.    (instvars <class>)
  228.       returns a list of the names of the instance variables of the class,
  229.       but not any inherited ones.
  230.   
  231. ALL-INSTVARS
  232.   
  233.    (all-instvars <class>)
  234.       returns a list of the names of instance variables, including 
  235.       inherited ones.
  236.       
  237. MIXINS
  238.   
  239.    (mixins <class>)
  240.       returns names of all of the class's parents.
  241.       
  242. RENAME-CLASS
  243.   
  244.    (rename-class (<old> <new>))
  245.       redefines <old> as <new>, replacing the internal name flags.
  246.       
  247. GETCV
  248.   
  249.    (getcv <class> <class-var>)
  250.       returns a gettable class-var.
  251.       
  252. SETCV
  253.   
  254.    (setcv <class> <class-var> <val>)
  255.       sets a settable class-var to val.
  256.       
  257. CLASS-COMPILED?
  258.       
  259.    (class-compiled? <class>)
  260.       returns #t if the class has been `compiled' already, either by
  261.       COMPILE-CLASS or automatically upon instance creation.
  262.       
  263. DESCRIBE
  264.   
  265.    (describe <instance-or-class>)
  266.       prints relevant information about either a class or an instance. If 
  267.       the class has not yet been `compiled' the information will be incomplete.
  268.       The information will, however, tell you whether the class has been
  269.       compiled.
  270.   
  271. SEND
  272.   
  273.    (send <instance> <message> <optional-arguments>)
  274.       evaluates <message> with respect to the class and instance and whatever
  275.       arguments are required. SEND causes an error if the class has no 
  276.       method for the message. You may prefer to use SEND-IF-HANDLES instead.
  277.       
  278. SEND-IF-HANDLES
  279.   
  280.    (send-if-handles <instance> <message> <optional-arguments>)
  281.       Send-if-handles returns #f if the method (message) is inappropiate,
  282.       otherwise behaves like SEND.
  283.       
  284. DEFINE-METHOD
  285.   
  286.    (define-method (<class> <method-name>) 
  287.         <lambda-list>
  288.           <body>)
  289.       defines a function that has access to class and instance variables 
  290.       for the class, including inherited ones. All such variables can be
  291.       regarded as lexical variables in scope for the body of the method;
  292.       the variables are also accessible by SET-name and GET-name methods
  293.       if these exist. Any methods accessible to the class can be called
  294.       as procedures within the body, so there is no need for a pseudo-
  295.       variable called SELF such as is provided by many other object-
  296.       oriented systems.
  297.       
  298. DELETE-METHOD
  299.   
  300.    (delete-method (<class> <method-name>))
  301.       destroys the named method of the given class.
  302.